<template>
	<uni-forms label-width="80px" :rules="rules" :model="formData" ref="form" validate-trigger="bind" err-show-type="undertext">
		<uni-forms-item name="faultReportExpl" required label="上报说明">
			<uni-easyinput type="textarea"  :inputBorder="true" v-model="formData.faultReportExpl"
				placeholder="请输入上报说明"></uni-easyinput>
		</uni-forms-item>
		<uni-forms-item name="faultReportUrl" required label="上报图片">
			<UploadImage
			  :uploadedImages="faultReportUrlList"
			  :uploadUrl="this.$baseUrl+'/api/files/upload'">
			</UploadImage>
		</uni-forms-item>
	</uni-forms>
	<button @click="submit" class="btn">提交</button>
</template>

<script>
	import request from '@/util/request';
	import UploadImage from '@/common/component/UploadImage.vue';
 	export default {
		components:{UploadImage},
        onLoad(options) {
            this.formData = JSON.parse(options.data)
			this.initdockPhotoList()
        },
        data() {
            return {
                formData: {},
				faultReportUrlList:[],
            }
        },
        methods: {
			initdockPhotoList() {
				this.faultReportUrlList = this.formData.faultReportUrl ? this.formData.faultReportUrl.split(',').map(url => {
					return {url}
				}) : [];
			},
            submit() {
				this.faultReportUrlList.forEach((item,index)=>{
					if(index==0){
						this.formData.faultReportUrl=item.url
					}else{
						this.formData.faultReportUrl+=","+item.url
					}
				})
				this.formData.faultReport = "1"
				request.post("/warn-record/edit", this.formData).then(res => {
					if (res.code === '200') {
						uni.showToast({
							title: "编辑成功",
							icon: 'success',
							duration: 2000
						});
					} else {
						uni.showToast({
							title: "编辑失败",
							icon: 'error',
							duration: 2000
						});
					}
				})
            }
        }
    }
</script>

<style scoped>
    .wd-cell {
        border-radius: 10px;
    }

    :deep(.wd-cell-group__body) {
        border-radius: 10px;
    }

    :deep(.wd-input) {
        border-radius: 10px;
    }

    .btn {
        margin: 20px;
        background-color: #007aff;
        color: white;
        text-align: center;
        border: none;
    }
</style>
